package com.foreknow.test;


import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

/**
 * 第一个Servlet服务器端应用程序
 */
public class FirstServlet extends HttpServlet {
    @Override
    public void init(ServletConfig config) throws ServletException {
        //如何获取到局部的初始化参数
        //String pageSize = config.getInitParameter("pageSize");
        //如何获取全局的初始化参数
        String pageSize = config.getServletContext().getInitParameter("pageSize");
        int page = Integer.parseInt(pageSize);
        System.out.println(page);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置服务器向客户端响应的内容的类型（MIME）
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out = resp.getWriter();
        out.println(new Date());
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
